228B - Two Tables - CodeForces Solution


brute force implementation *1400

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>

using namespace std;


bool ok(int x, int y, int R, int C){
    return 0 <= x && x < R && 0 <= y && y < C;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Ra, Ca; cin >> Ra >> Ca;
    vector<string> a(Ra);
    for(int i = 0; i < Ra; i ++) cin >> a[i];

    int Rb, Cb; cin >> Rb >> Cb;
    vector<string> b(Rb);
    for(int i = 0; i < Rb; i ++) cin >> b[i];

    int res = -1, resx = -1, resy = -1;
    for(int x = -max(Ra, Rb); x <= max(Ra, Rb); x ++)
        for(int y = -max(Ca, Cb); y <= max(Ca, Cb); y ++){
            int tres = 0;
            for(int ii = 0; ii < Ra; ii ++)
                for(int jj = 0; jj < Ca; jj ++){
                    if(ok(ii + x, jj + y, Rb, Cb))
                        tres += (a[ii][jj] - '0') * (b[ii + x][jj + y] - '0');
                }
            if(tres > res) res = tres, resx = x, resy = y;
        }
//    cout << res << '\n';
    cout << resx << ' ' << resy << '\n';

    return 0;
}


Comments

Submit
0 Comments
More Questions

1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals